//
//  YQBigVisaCtl.m
//  OverseasImmigration
//
//  Created by yuqin on 2019/6/8.
//  Copyright © 2019年 yuqin. All rights reserved.
//

#import "YQBigVisaCtl.h"
#import "YQBigVisaCell.h"
#import "YQBigVisaModel.h"
#import "YQBigVidaDetailCtl.h"

@interface YQBigVisaCtl ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

@property (nonatomic, strong) UITableView *visaTableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation YQBigVisaCtl

- (NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden = NO;
    self.title = @"签证中心";
    //创建UI
    [self setupBigVisaView];
    //获取数据
    [self loadBigVisaData];
}

- (void)loadBigVisaData {
    [[HTTPRequstManger sharedHTTPRequstManger] getRequestWithUrlString:YQ_String_Url(@"user/visa/list") appendParameters:nil successBlock:^(id responseObject) {
        NSArray *data = responseObject[@"data"];
        for (NSDictionary *dict in data) {
            YQBigVisaModel *model = [YQBigVisaModel mj_objectWithKeyValues:dict];
            
            [self.dataArr addObject:model];
        }
        [self.visaTableView reloadData];
    } failureBlock:^(NSError *error) {
        
    }];
}

- (void)setupBigVisaView {
    self.visaTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, SCREENWIDTH, kTableViewHeight) style:UITableViewStylePlain];
    self.visaTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.visaTableView.delegate = self;
    self.visaTableView.dataSource = self;
    self.visaTableView.tableFooterView = [[UIView alloc] init];
    YQ_EmptyView(self.visaTableView);
    [self.visaTableView registerNib:[UINib nibWithNibName:YQ_BIG_VISA_CELL bundle:nil] forCellReuseIdentifier:YQ_BIG_VISA_CELL];
    [self.view addSubview:self.visaTableView];
}

YQ_Empty_Deletage_DataSources(@"暂无数据");

#pragma mark - 代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return FIT(200);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YQBigVisaCell *cell = [tableView dequeueReusableCellWithIdentifier:YQ_BIG_VISA_CELL forIndexPath:indexPath];
    YQBigVisaModel *model = self.dataArr[indexPath.row];
    cell.visaModel = model;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    YQBigVisaModel *model = self.dataArr[indexPath.row];
    YQBigVidaDetailCtl *ctl = [[YQBigVidaDetailCtl alloc] init];
    ctl.idStr = model.id;
    YQ_PUSH(ctl);
}

@end
